// Zepto
var $ = require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');
var isPassive=require('./components/iscroll/demoUtils');

module.exports = $;

// 引入Swiper

var Swiper = require('./components/swiper/swiper.min.js');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min.js');
var IScroll=require('./components/iscroll/iscroll.js');

var swiper = new Swiper ('.swiper-container', {
  onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
    swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
    swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
  }, 
  onSlideChangeEnd: function(swiper){ 
    swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
  } 
}) 


    $("#mainContainer").hide();
    $(".swiper-container").hide();
// jquery/zepto
$("#enter").tap(function(){
    $(".swiper-container").hide();
    $("#mainContainer").show();
    $('#header').html('skill');
    $.ajax({
        type:'GET',
        url:'http://localhost:8000/api/skill.php',
        dataType:'json',
        success:function(data){
            var html = "";
            for(var i=0;i<data.length;i++){
                html +="<li>" + data[i].name + "</li>";
            }
            $("#scroller ul").html(html);
            
            load();
            
        }
    })
    var load=function(){
        var myScroll;
        var $width=$('#wrapper').height();
        console.log(1);
        console.log($width);

        myScroll = new IScroll('#wrapper', {
            scrollbars: true,
            mouseWheel: true,
            interactiveScrollbars: true,
            shrinkScrollbars: 'scale',
            fadeScrollbars: true            
        });
        
        document.addEventListener('touchmove', function (e) { 
            if (e.cancelable) {       
                if (!e.defaultPrevented) {
                    e.preventDefault();
                }
            }
            
        }, isPassive() ? {
                capture: false,
                passive: false
            } : false);
    }
    
	
//	以上为滚动条滚动
   

   $("footer ul li").tap(function(){
    var apiTarget = $(this).attr('id');
    $('#header').html(apiTarget);

    var apiUrl = "http://localhost:8000/api/" + apiTarget + ".php";
    console.log(apiUrl)
    $.ajax({
        type:'GET',
        url:apiUrl,
        success:function(data){
            var html = "";
            for(var i=0;i<data.length;i++){
                html +="<li>" + data[i].name + "</li>";
            }
            $("#scroller ul").html(html);
        }
    })

})
  
	




   
})

    


var interval  = setInterval(function(){
    if(document.readyState === 'complete'){
        clearInterval(interval);
        $("#loading").hide();
        $(".swiper-container").show();
        swiper.updateContainerSize(); // 万分重要
        swiper.updateSlidesSize(); // 万分重要
    }else{
        $("#loading").show();
    }
})

